<?php

namespace catchAdmin\customs\model;


use catchAdmin\externalGoods\model\GoodsAttribute;
use catchAdmin\externalGoods\model\GoodsRule as externalGoodsRuleModel;
use catcher\base\CatchModel;
use catcher\CatchAuth;


class XsOrder extends CatchModel
{

    protected $name = 'db_customs_xs_order';

    protected $json = [
        'subMerchantOrderDetails',
        '_ext_data',
        '_return_data',
        '_customsApply_data',
        'customsApply_param',
        'customsApply_return',
        'payInfo'
    ];
    // 设置JSON数据返回数组
    protected $jsonAssoc = true;

    protected $field = [
          'id',
          'orderId',
          'merOrderId',
          'displayName',
          'goodsName',
          'goodsCount',
          'goodsType',
          'orderAmount',
          'orderCurrencyCode',
          'tradeType',
          'payType',
          'orgCode',
          'payerAccount',
          'payCurrencyCode',
          'settleCurrencyCode',
          'shareFlag',
          'subMerchantOrderDetails',
          'returnUrl',
          'noticeUrl',
          'toReturnUrl',
          'toNoticeUrl',
          'toNoticeUrl2',
          'platformId',
          'customerId',
          'customerType',
          'customerName',
          'customerIdNo',
          'customerTel',
          'bankCardNo',
          'bankCardType',
          'expireData',
          'cvn',
          'remark',
          'reserve1',
          'reserve2',
          'preOrderFlag',
          'declareCheck',
          'dealId',
          'status',
          'completeTime',
          'payAmount',
          '_ext_data',
          '_return_data',
          '_customsApply_data',
          'customsApply_status',
          'customsApply_param',
          'customsApply_return',
          'created_at',
          'updated_at',
          'deleted_at',
          'tenant_id',
          'creator_id',
          'payInfo',
          'checkOrg',//验核机构
          'checkOrgOrderNo',//验核机构交易号
    ];

    public function getList($tenant_id = 0)
    {
        $where = [];
        if($tenant_id !== 0){
            $where[]=['tenant_id','=',$tenant_id];
        }

        return $this
            ->withoutField('updated_at,deleted_at,tenant_id')
            ->catchSearch()
            ->where($where)
            ->order($this->aliasField('id'), 'desc')
            ->paginate()
            ->each(function (&$item) {

                $item['orderAmount'] = number_format($item['orderAmount'] / 100,2);
            });
    }
}